<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>LB-Admin1.0</title>
        {include file="header"}
        <style>
            .list-sort-input{width:40px;padding:3px;border:1px solid #ccc}
        </style>
    </head>
    <body>
    <div class="x-nav">
        <div class="layui-breadcrumb" style="float: left;">
            <!--<a onclick="history.back()"><i class="layui-icon layui-icon-prev"></i></a>-->
            <a>首页</a>
            <a>菜单管理</a>
        </div>      
        <div style="float: right;">            
            <a onclick="xadmin.open('添加','{:url("add")}')"><button class="layui-btn"><i class="layui-icon">&#xe61f;</i>添加</button></a>
            <button class="layui-btn layui-btn-danger" style="margin-left:5px" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button>
            <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
                <i class="layui-icon layui-icon-refresh-1"></i></a>
        </div>
    </div>
    <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <div class="think-box-shadow">
    {empty name='list'}
    <blockquote class="layui-elem-quote">没 有 记 录 哦！</blockquote>
    {else}
    <table class="layui-table layui-form" lay-skin="line">
        <thead>
        <tr>
            <th style="width: 25px;">
                <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary">
            </th>
            <th style="width: 25px;"></th>
            <th  style="width: 25px;"></th>
            <th>名称</th>
            <th>应用</th>
            <th>控制器</th>
            <th>方法</th>
            <th class='layui-hide-xs' style="width:80px"></th>
            <th style="width:250px"></th>
        </tr>
        </thead>
        <tbody>
        {foreach $list as $key=>$vo}
        <tr data-dbclick>
            <td class='list-table-check-td think-checkbox'>
                <input type="checkbox" name="id" value="{$vo.id}" lay-skin="primary">
            </td>
            <td class='list-table-sort-td'>
                <input onblur="setsort(this.value,{$vo.id})"  value="{$vo.sort}" class="list-sort-input">
            </td>
            <td class='text-center'><i class="{$vo.icon} font-s18"></i></td>
            <td class="nowrap"><span class="color-desc">{$vo.spl|raw}</span>{$vo.title}</td>
            <td class='layui-hide-xs'>{$vo.appname}</td>
            <td class='layui-hide-xs'>{$vo.controller}</td>
            <td class='layui-hide-xs'>{$vo.method}</td>
            <td class='text-center nowrap'>{eq name='vo.status' value='0'}<span class="color-red">已禁用</span>{else}<span class="color-green">使用中</span>{/eq}</td>
            <td class='text-center nowrap notselect'>{if $vo.level<2}               
                <a class="layui-btn layui-btn-xs layui-btn-primary" onclick="xadmin.open('添加子菜单','{:url("add")}?pid={$vo.id}')">添 加</a>{else}
                <a class="layui-btn layui-btn-xs layui-btn-disabled">添 加</a>{/if}
                <a data-dbclick class="layui-btn layui-btn-xs"  onclick="xadmin.open('编辑菜单','{:url("form")}?id={$vo.id}')">编 辑</a>              
                {if $vo.status==1}
                <a class="layui-btn layui-btn-warm layui-btn-xs" onclick="setStatus(0,{$vo.id})">禁 用</a> 
                {else}
                <a class="layui-btn layui-btn-normal layui-btn-xs" onclick="setStatus(1,{$vo.id})">启 用</a>
                {/if}
                <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="remove({$vo.id},{$vo.level})">删 除</a>
            </td>
        </tr>
        {/foreach}
        </tbody>
    </table>
    {/empty}
</div>
<!--list end-->
</div></div></div></div></div>
<script>
    function setsort(v,id)
    {
        $.post('{:url('setsort')}',{id:id,sort:v},function(res){
            console.log(res)
            if(res.code==1)
            {
                layer.msg('设置成功',{icon:1,time:500},function(){
                    location.reload();
                })                
                return
            }
            layer.msg('设置失败')
        })
    }
    function setStatus(n,id)
    {
        $.post('{:url('status')}',{id:id,status:n},function(res){
            console.log(res)
            if(res.code==1)
            {
                layer.msg('修改成功',{icon:1,time:1000},function(){
                    location.reload();
                })                
                return
            }
            layer.msg('修改失败')
        })
    }
    function remove(id,leve)
    {
        $.post('{:url('remove')}',{id:id,leve:leve},function(res){
            console.log(res)
            if(res.code==1)
            {
                layer.msg('修改成功',{icon:1,time:1000},function(){
                    location.reload();
                })                
                return
            }
            layer.msg('修改失败')
        })
    }
    function delAll(argument) {
        var ids = [];
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
               ids.push($(this).val())
            }
        });
        if(ids.length==0)
        {
            layer.msg("请选择项目")
            return;
        }
        layer.confirm('确认要删除所选吗？', function (index) {
            layer.close(index);
            $.ajax({
                type: "POST",
                url: "{:url('removeall')}",
                data: { "id": ids },
                datatype: "json",
                success: function (res, textStatus) {                   
                    if (res.code == 1) {
                        layer.msg(res.msg, { icon: 1, time: 2000 });
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    }
                    else {
                        layer.alert(res.msg, { icon: 5 });
                        return false;
                    }
                },
                error: function (e) {
                    layer.alert('系统出现错误,请检查系统！', { icon: 2 });//0感叹号  1打勾  2打叉  3问号  4锁头  5难过  6笑脸
                    return false;
                }
            });
        });
    }
    layui.use(['laydate','form'], function(){        
        var  form = layui.form;
        form.on('checkbox(checkall)', function(data){
          if(data.elem.checked){
            $('tbody input').prop('checked',true);
          }else{
            $('tbody input').prop('checked',false);
          }
          form.render('checkbox');
        }); 
        
        // var laydate = layui.laydate;
        // laydate.render({
        //   elem: '#start'
        // });
        // laydate.render({
        //   elem: '#end'
        // });
      });
</script>
{include file="footer"}
